﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LapSim {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void TrackButton_Click( object sender, RoutedEventArgs e ) {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = string.Empty;
            dlg.DefaultExt = ".AIW";
            dlg.Filter = "rFactor 1 track geometry (.AIW)|*.AIW";

            Nullable<bool> result = dlg.ShowDialog();

            if ( result != true ) return;

            TrackData t = new TrackData( dlg.FileName );
            TrackGraphic g = new TrackGraphic();

            ImgTrack.UpdateLayout();
            g.w = (int)Math.Round(myCanvas.ActualWidth);
            g.h = (int)Math.Round(myCanvas.ActualHeight);

            g.DrawTrack( t );
            ImgTrack.Source = g.GetBmpSrc();
        }
    }
}
